package mumu.android.app;

import java.util.Observable;
import java.util.Observer;

import mumu.android.R;
import mumu.android.lib.app.MyDown;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class ZZdemoActivity extends Activity implements OnClickListener, Observer {

	private TextView tv;
	private Button btn;
	private MyDown down;
	private static final int OK = 1;
	private Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			if (msg.what == OK)
				tv.setText(msg.obj.toString());
		}
	};

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.observer);
		tv = (TextView) findViewById(R.id.textview1);
		btn = (Button) findViewById(R.id.button1);
		btn.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {
		down = new MyDown();
		down.addObserver(this);
		down.downCancle();
		down.downOver();
		down.downRunning();
	}

	@Override
	public void update(Observable observable, Object data) {
		if (data instanceof String) {
			Message mes = new Message();
			mes.what = OK;
			mes.obj = data;
			handler.sendMessage(mes);// 注意：此处要用handler来更新页面内容
		}
	}
}